<?php
namespace app\common\model;

use think\Model;

class FengshuiXuankongLog extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'createtime_text',
        'sex_text',
        'yun_model_text',
        'shan_model_text'
    ];
    
    // 性别文字
    public function getSexTextAttr($value, $data)
    {
        $list = [0 => '男', 1 => '女'];
        return isset($list[$data['sex']]) ? $list[$data['sex']] : '';
    }
    
    // 元运文字
    public function getYunModelTextAttr($value, $data)
    {
        $list = [
            0 => '一运',
            1 => '二运',
            2 => '三运',
            3 => '四运',
            4 => '五运',
            5 => '六运',
            6 => '七运',
            7 => '八运',
            8 => '九运'
        ];
        return isset($list[$data['yun_model']]) ? $list[$data['yun_model']] : '';
    }
    
    // 山向文字
    public function getShanModelTextAttr($value, $data)
    {
        $list = [
            0 => '壬山丙向',
            1 => '子山午向',
            2 => '丑山未向',
            3 => '艮山坤向',
            4 => '寅山申向',
            5 => '卯山酉向',
            6 => '辰山戌向',
            7 => '巽山乾向',
            8 => '巳山亥向',
            9 => '午山子向',
            10 => '未山丑向',
            11 => '坤山艮向',
            12 => '申山寅向',
            13 => '酉山卯向',
            14 => '戌山辰向',
            15 => '乾山巽向',
            16 => '亥山巳向'
        ];
        return isset($list[$data['shan_model']]) ? $list[$data['shan_model']] : '';
    }
    
    // 创建时间文字
    public function getCreatetimeTextAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['createtime']);
    }
}